package com.example.administrator.szb.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.szb.R;
import com.example.administrator.szb.bean.GWXQBean;
import com.example.administrator.szb.util.QTLog;
import com.example.administrator.szb.view.FlowLayout;

import java.util.List;

/**
 * Created by stone on 2018/1/8.
 */

public class JGDetailAdapter extends android.widget.BaseAdapter{

    private List list;
    private Context context;
    private LayoutInflater inflater;

    public JGDetailAdapter(List list, Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(this.context);
        QTLog.e("list"+list.size());
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public GWXQBean.DataBean.BusinessBean.NextBeanX getItem(int position) {
        return (GWXQBean.DataBean.BusinessBean.NextBeanX)list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = inflater.inflate(R.layout.item_jgxq,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        GWXQBean.DataBean.BusinessBean.NextBeanX beanX = getItem(position);
        holder.textView.setText(beanX.getTitle());
        holder.recyclerView.setLayoutManager(new GridLayoutManager(context,3));
        holder.recyclerView.setAdapter(new JGDetailTextAdapter(beanX.getNext(),context));
        holder.myFlowLayout.removeAllViews();

        //view.removeView(textViews);
        for (int i=0;i<beanX.getNext().size();i++){
            LinearLayout view = (LinearLayout )inflater.inflate(R.layout.item_text,null);
            TextView textViews = view.findViewById(R.id.textViews);
            if (beanX.getNext().get(i).getGenre()==1){
                textViews.setTextColor(context.getResources().getColor(R.color.black1));
            }else {
                textViews.setTextColor(context.getResources().getColor(R.color.gray1));
            }
            textViews.setText(beanX.getNext().get(i).getTitle());
            view.removeAllViews();

            holder.myFlowLayout.addView(textViews);
        }
        return convertView;
    }

    class ViewHolder{
        FlowLayout myFlowLayout;
        TextView textView;
        RecyclerView recyclerView;
        public ViewHolder(View view) {
           textView = view.findViewById(R.id.item_textView);
            recyclerView = view.findViewById(R.id.recyclerView);
            myFlowLayout = view.findViewById(R.id.myFlowLayout);
        }
    }
}
